Micron Document
🎖️GitЯра🎖️

Node / meshtastic / Meshtastic-Android / files / core / data / src / commonMain / kotlin / org / meshtastic / core / data / repository / EventFirmwareRepositoryImpl.kt

Displaying Raw • Download

core/data/src/commonMain/kotlin/org/meshtastic/core/data/repository/EventFirmwareRepositoryImpl.kt bf929c20f274232e0eb8ddc19b2dc82403e99e5b (bf929c20) Text, 2.91 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.data.repository

Tff7b72import T7ee787co.touchlab.kermit.Logger
Tff7b72import T7ee787kotlinx.coroutines.sync.Mutex
Tff7b72import T7ee787kotlinx.coroutines.sync.withLock
Tff7b72import T7ee787kotlinx.coroutines.withContext
Tff7b72import T7ee787kotlinx.serialization.json.Json
Tff7b72import T7ee787org.koin.core.annotation.Single
Tff7b72import T7ee787org.meshtastic.core.common.util.safeCatching
Tff7b72import T7ee787org.meshtastic.core.data.datasource.BundledAssetReader
Tff7b72import T7ee787org.meshtastic.core.data.datasource.decode
Tff7b72import T7ee787org.meshtastic.core.di.CoroutineDispatchers
Tff7b72import T7ee787org.meshtastic.core.model.EventFirmwareEdition
Tff7b72import T7ee787org.meshtastic.core.model.EventFirmwareResponse
Tff7b72import T7ee787org.meshtastic.core.repository.EventFirmwareRepository
Tff7b72import T7ee787kotlin.concurrent.Volatile

T8b949e/**
* ponytail: bundled-only — the snapshot is a handful of static records, so it's decoded once into memory with no DB or
* network refresh (unlike [DeviceLinkRepositoryImpl]). Add a `/resource/eventFirmware` refresh when that API ships.
*/
Tf0883e@Single
Tff7b72class T56d364EventFirmwareRepositoryImplTb4b4b4(
Tff7b72private Tff7b72val Te6edf3assetReaderTb4b4b4: Te6edf3BundledAssetReaderTb4b4b4,
Tff7b72private Tff7b72val Te6edf3jsonTb4b4b4: Te6edf3JsonTb4b4b4,
Tff7b72private Tff7b72val Te6edf3dispatchersTb4b4b4: Te6edf3CoroutineDispatchersTb4b4b4,
Tb4b4b4) Tb4b4b4: Te6edf3EventFirmwareRepository Tb4b4b4{

Tff7b72private Tff7b72val Te6edf3mutex Tff7b72= Te6edf3MutexTb4b4b4(Tb4b4b4)

Tf0883e@Volatile Tff7b72private Tff7b72var Te6edf3cacheTb4b4b4: Te6edf3MapTff7b72<Tffa657StringTb4b4b4, Te6edf3EventFirmwareEditionTff7b72>Tff7b72? Tff7b72= Tff7b72null

Tff7b72override Tff7b72suspend Tff7b72fun Td2a8ffgetEditionTb4b4b4(Te6edf3editionNameTb4b4b4: Tffa657StringTb4b4b4)Tb4b4b4: Te6edf3EventFirmwareEdition? Tff7b72= Te6edf3loadTb4b4b4(Tb4b4b4)Tff7b72[Te6edf3editionNameTff7b72]

T8b949e/**
* Decodes the bundled snapshot once, keyed by edition name. Empty (not crashing) if the asset is absent/malformed.
*/
Tff7b72private Tff7b72suspend Tff7b72fun Td2a8ffloadTb4b4b4(Tb4b4b4)Tb4b4b4: Te6edf3MapTff7b72<Tffa657StringTb4b4b4, Te6edf3EventFirmwareEditionTff7b72> Tb4b4b4{
Te6edf3cacheTff7b72?.Te6edf3let Tb4b4b4{
Tff7b72return Tffa657it
Tb4b4b4}
Tff7b72return Te6edf3mutexTb4b4b4.Te6edf3withLock Tb4b4b4{
Te6edf3cache
Tff7b72?: Te6edf3withContextTb4b4b4(Te6edf3dispatchersTb4b4b4.Te6edf3ioTb4b4b4) Tb4b4b4{
Te6edf3safeCatching Tb4b4b4{ Te6edf3assetReaderTb4b4b4.Te6edf3decodeTff7b72<Te6edf3EventFirmwareResponseTff7b72>Tb4b4b4(Te6edf3ASSET_NAMETb4b4b4, Te6edf3jsonTb4b4b4)Tff7b72?.Te6edf3editionsTb4b4b4.Te6edf3orEmptyTb4b4b4(Tb4b4b4) Tb4b4b4}
Tb4b4b4.Te6edf3onFailure Tb4b4b4{ Te6edf3e Tff7b72-Tff7b72> Te6edf3LoggerTb4b4b4.Te6edf3wTb4b4b4(Te6edf3eTb4b4b4) Tb4b4b4{ Ta5d6ff"Ta5d6ffEventFirmwareRepository: failed to read bundled JSONTa5d6ff" Tb4b4b4} Tb4b4b4}
Tb4b4b4.Te6edf3getOrDefaultTb4b4b4(Te6edf3emptyListTb4b4b4(Tb4b4b4)Tb4b4b4)
Tb4b4b4.Te6edf3associateBy Tb4b4b4{ Tffa657itTb4b4b4.Te6edf3edition Tb4b4b4}
Tb4b4b4}
Tb4b4b4.Te6edf3also Tb4b4b4{ Te6edf3cache Tff7b72= Tffa657it Tb4b4b4}
Tb4b4b4}
Tb4b4b4}

Tff7b72private Tff7b72companion Tff7b72object Tb4b4b4{
Tff7b72private Tff7b72const Tff7b72val Te6edf3ASSET_NAME Tff7b72= Ta5d6ff"Ta5d6ffevent_firmware.jsonTa5d6ff"
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.06s